//添加到OnPlayerRespawn.sqf
fnc_lockVeh0 = {
	if(isNull cursorTarget || {!alive cursorTarget}) exitwith {false};
	if((player distance cursorTarget)>8) exitwith {false};
	if(cursorTarget isKindOf "Car" || {cursorTarget isKindOf "Tank"} || {cursorTarget isKindOf "Air"}) exitwith{
		(count crew cursorTarget == 0) && {isNull (cursorTarget getVariable ["as_lock_unit", objNull])}
	};
	false
};

fnc_lockVeh1 = {
	if(isNull cursorTarget || {!alive cursorTarget}) exitwith {false};
	if((player distance cursorTarget)>8) exitwith {false};
	if(cursorTarget isKindOf "Car" || {cursorTarget isKindOf "Tank"} || {cursorTarget isKindOf "Air"}) exitwith{player == (cursorTarget getVariable ["as_lock_unit", objNull])};
	false
};


player addAction ["<t color=""#fff100"">锁定载具 </t>", 
{
	cursorTarget setVariable ["as_lock_unit", player, true];
}, [], -997, false, true, "", "call fnc_lockVeh0"];


player addAction ["<t color=""#d50e0e"">解锁载具 </t>", 
{
	cursorTarget setVariable ["as_lock_unit", objNull, true];
}, [], -997, false, true, "", "call fnc_lockVeh1"];


player removeAllEventHandlers "GetInMan";
player addEventHandler ["GetInMan", {
	params ["_unit", "_role", "_veh", "_turret"];
	//不是司机不限制
	if(driver _veh != player) exitWith{};
	
	private _lock = _veh getVariable ["as_lock_unit", objNull];
	if((!isNull _lock) && {!(_lock in crew _veh)})then{
		if(_lock distance _veh > 500)then{
			//远离自动解锁
			_veh setVariable ["as_lock_unit", objNull, true];
		}else{
			hint format["载具已被 %1锁定！", name _lock];
			moveOut player;
			/*
			[] spawn {
				waitUntil{Sleep 1;moveOut player; player == vehicle player}
			};
			*/
		};
	};		
}];

player removeAllEventHandlers "SeatSwitchedMan";
player addEventHandler ["SeatSwitchedMan", {
	params ["_unit1", "_unit2", "_veh"];
	//切换到司机限制
	if(driver _veh == player)then{
		private _lock = _veh getVariable ["as_lock_unit", objNull];
		if((!isNull _lock) && {!(_lock in crew _veh)})then{
			hint format["载具已被 %1锁定！", name _lock];
			moveOut player;
		};
	};
}];